package org.example.demo01.controller;

import org.example.demo01.service.DispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/dispatches")
public class DispatchController {
    @Autowired private DispatchService dispatchService;

    @PutMapping("/{wsid}/start")
    public ResponseEntity<String> startProcessing(@PathVariable String wsid) {
        return ResponseEntity.ok(dispatchService.startProcessing(wsid));
    }

    @PutMapping("/{wsid}/pause")
    public ResponseEntity<String> pauseProcessing(@PathVariable String wsid) {
        return ResponseEntity.ok(dispatchService.pauseProcessing(wsid));
    }

    @PutMapping("/{wsid}/resume")
    public ResponseEntity<String> resumeProcessing(@PathVariable String wsid) {
        return ResponseEntity.ok(dispatchService.resumeProcessing(wsid));
    }

    @PutMapping("/{wsid}/finish")
    public ResponseEntity<String> finishProcessing(@PathVariable String wsid) {
        return ResponseEntity.ok(dispatchService.finishProcessing(wsid));
    }

    @GetMapping("/{wsid}/status")
    public ResponseEntity<String> getWorkstationStatus(@PathVariable String wsid) {
        return ResponseEntity.ok(dispatchService.getWorkstationStatus(wsid));
    }
    @GetMapping("/schedule")
    public ResponseEntity<String> schedulePieces() {
        dispatchService.schedulePieces();
        return ResponseEntity.ok("Products scheduled successfully!");
    }
}